#include <stdio.h>
#include <string.h>

//罗马数字转整数
int roman(char s)//直接传入字符
{
    switch (s)
    {
    case 'I':
        return 1;
    case 'V':
        return 5;
    case 'X':
        return 10;
    case 'L':
        return 50;
    case 'C':
        return 100;
    case 'D':
        return 500;
    case 'M':
        return 1000;
    default:
        return 0; 
    }
}

int romanToInt(char *s)
{
    int len = strlen(s);
    int All_Num = 0;

    for (int i = len-1; i >= 0; i--)
    {
        int num = roman(s[i]);
        if (roman(s[i]) >= roman(s[i+1]))
        {
            All_Num += num;
        }
        else
        {
            All_Num -= num;
        }  
    }
    return All_Num;
}

int main()
{
    char *s = "CM";
    int ret = romanToInt(s);
    printf("%d\n", ret);
    return 0;
}
